/*
 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva.
 *
 * This file may be distributed under the terms of the Q Public License
 * as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

package net.sf.fmj.media;

import java.awt.Component;
import java.awt.Rectangle;

import javax.media.Buffer;
import javax.media.control.FrameGrabbingControl;
import javax.media.renderer.VideoRenderer;

/**
 * Abstract implementation of VideoRenderer, useful for subclassing.
 * 
 *
 */
public abstract class AbstractVideoRenderer extends AbstractRenderer implements VideoRenderer, FrameGrabbingControl
{

	private Rectangle bounds = null;
	
	public Rectangle getBounds()
	{
		return bounds;
	}

	public abstract Component getComponent();

	public void setBounds(Rectangle rect)
	{	this.bounds = rect;
	}

	public boolean setComponent(Component comp)
	{
		// default implementation does not allow changing of component.
		return false;
	}
	
	private Buffer lastBuffer;
	@Override
	public final int process(Buffer buffer)
	{
		lastBuffer = buffer; // TODO: clone?
		return doProcess(buffer);
	}

	protected abstract int doProcess(Buffer buffer);
	public Component getControlComponent()
	{
		return null;
	}

	public Buffer grabFrame()
	{
		return lastBuffer;
	}

}
